﻿namespace Compass.Maui.Services.FinishGoods;

public interface IPackingListService:IBaseService<PackingListDto>
{
    Task<PackingListDto?> GetPackingListDtoByMainPlanIdAsync(Guid mainPlanId);
    
    Task<List<PackingListDto>> GetPackingListDtosAsync(int skip, int take, string? search= null);
    Task<PackingListDto?> GetPackingListDtoByOdpNumberAsync(string odpNumber);
}
public class PackingListService :BaseService<PackingListDto>, IPackingListService
{
    private const string ServiceName = "PackingList";
    private readonly IHttpRestClient _client;
    public PackingListService(IHttpRestClient client) : base(client,ServiceName)
    {
        _client = client;
    }
    public async Task<PackingListDto?> GetPackingListDtoByMainPlanIdAsync(Guid mainPlanId)
    {
        var request = new BaseRequest
        {
            Method = Method.Get,
            Route = $"{ServiceName}/Maui/MainPlan/{mainPlanId}",
        };
        var response = await _client.ExecuteAsync<PackingListDto>(request);
        return response.Status ? response.Result : null;
    }

    public async Task<List<PackingListDto>> GetPackingListDtosAsync(int skip, int take, string? search = null)
    {
        var strSearch = string.IsNullOrEmpty(search) ? "" : $"&search={search}";
        var request = new BaseRequest
        {
            Method = Method.Get,
            Route = $"{ServiceName}/Maui/All?skip={skip}&take={take}{strSearch}",
        };
        var response = await _client.ExecuteAsync<List<PackingListDto>>(request);
        return response.Status ? response.Result : new List<PackingListDto>();
    }

    public async Task<PackingListDto?> GetPackingListDtoByOdpNumberAsync(string odpNumber)
    {
        var request = new BaseRequest
        {
            Method = Method.Get,
            Route = $"{ServiceName}/Maui/OdpNumber?odpNumber={odpNumber}",
        };
        var response = await _client.ExecuteAsync<PackingListDto>(request);
        return response.Status ? response.Result : null;
    }
}